using System.Linq;
using DNT.RavenQA.Core.Models;
using Raven.Client;

namespace DNT.RavenQA.Web.Infrastructure.QueryModel
{
    public class LatestQuestionsQuery : IQuery<Question>
    {
        public IQueryable<Question> ExecuteWithStats(IDocumentSession session, out RavenQueryStatistics stats)
        {
            return QuestionQueryHelper.GetBaseQuery(session)
                .Statistics(out stats)
                .OrderByDescending(question => question.PostedOn);
        }

        public IQueryable<Question> Execute(IDocumentSession session)
        {
            return QuestionQueryHelper.GetBaseQuery(session)
                .OrderByDescending(question => question.PostedOn);
        }
    }
}